package com.carhailing.alipay.config;

import com.alipay.api.AlipayConfig;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * 支付宝 支付配置类，读取配置文件
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "alipay")
// 读取本地
//@PropertySource("classpath:alipay.properties")
//@Value("${}")
public class AliPayResource {
   private String gatewayUrl;      // 支付宝网关地址
   private String appId;           // 沙箱应用,appId
   private String merchantPrivateKey; // 商户的支付宝私钥
   private String alipayPublicKey; // 商户的支付宝公钥
   private String signType;        // 签名方式，加密算法
   private String charset;         // 字符编码格式
   private String notifyUrl;       // 回调通知路径
   private String returnUrl;       // 异步通知路径

   /**
    * 给 alipayConfig 赋值；主动查询支付结果用
    *
    * @return
    */
   public AlipayConfig getAlipayConfig() {
      AlipayConfig alipayConfig = new AlipayConfig();
      alipayConfig.setServerUrl(gatewayUrl);
      alipayConfig.setAppId(appId);
      alipayConfig.setPrivateKey(merchantPrivateKey);
      alipayConfig.setAlipayPublicKey(alipayPublicKey);
      alipayConfig.setFormat("json");
      alipayConfig.setCharset(charset);
      alipayConfig.setSignType(signType);
      return alipayConfig;
   }
}